package com.clinic.entity.db;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = DrugStock.TABLE)
public class DrugStock implements Serializable{
	
	private static final long serialVersionUID = -899234965816789224L;

	public static final String TABLE = "drugstock";
	
	public static final class Columns {
		public static final String DRUG_STOCK_ID = "drugStockId";
		public static final String EXPIRE_DATE = "expireDate";
		public static final String ORDER_AMOUNT = "orderAmount";
		public static final String STOCK_AMOUNT = "stockAmount";
		public static final String DRUG_ISSUE_ID = "drugIssueId";
		public static final String DRUG_ID = "drugId";
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = Columns.DRUG_STOCK_ID)
	private long drugStockId;
	
	@Column(name = Columns.EXPIRE_DATE)
	private Date expireDate;
	
	@Column(name = Columns.ORDER_AMOUNT)
	private int orderAmount;
	
	@Column(name = Columns.STOCK_AMOUNT)
	private int stockAmount;
	
	@ManyToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name="drugstockissue",
	    joinColumns={@JoinColumn(name="drugStockId")},
	    inverseJoinColumns={@JoinColumn(name="drugIssueId")})
	private Set<DrugIssue> drugIssues;

	@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = Columns.DRUG_ID)
	private Drug drug;

	public long getDrugStockId() {
		return drugStockId;
	}

	public void setDrugStockId(long drugStockId) {
		this.drugStockId = drugStockId;
	}

	public Date getExpireDate() {
		return expireDate;
	}

	public void setExpireDate(Date expireDate) {
		this.expireDate = expireDate;
	}

	public int getOrderAmount() {
		return orderAmount;
	}

	public void setOrderAmount(int orderAmount) {
		this.orderAmount = orderAmount;
	}

	public int getStockAmount() {
		return stockAmount;
	}

	public void setStockAmount(int stockAmount) {
		this.stockAmount = stockAmount;
	}

	public Set<DrugIssue> getDrugIssues() {
		return drugIssues;
	}

	public void setDrugIssues(Set<DrugIssue> drugIssues) {
		this.drugIssues = drugIssues;
	}

	public Drug getDrug() {
		return drug;
	}

	public void setDrug(Drug drug) {
		this.drug = drug;
	}

}
